//
//  ViewController.swift
//  关键帧动画飞机降落
//
//  Created by app on 2017/4/13.
//  Copyright © 2017年 app. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    var airportImageView: UIImageView!
    var planImageView: UIImageView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        airportImageView = UIImageView()
        airportImageView.frame = UIScreen.main.bounds
        airportImageView.image = UIImage(named: "Airport")
        view.addSubview(airportImageView)
        
        planImageView = UIImageView()
        planImageView.image = UIImage(named: "Plane")
        planImageView.frame = CGRect(x: 100, y: 100, width: 50, height: 40)
        planImageView.contentMode = .scaleAspectFit
        view.addSubview(planImageView)
        
       
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        UIView.animateKeyframes(withDuration: 2, delay: 0, options: .calculationModeCubic, animations: { 
            
            UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 1/2, animations: { 
                self.planImageView.frame = CGRect(x: 300, y: 100, width: 30, height: 30)
            })
            
            UIView.addKeyframe(withRelativeStartTime: 1/2, relativeDuration: 1/2, animations: { 
                self.planImageView.frame = CGRect(x: 300, y: 300, width: 100, height: 100)
            })
            
        }) { (_) in
            
        }
    }
}

